package com.praveen.reminder;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ExpandableListView;

@SuppressWarnings("unused")
public class ReminderAppActivity extends Activity {

	private static final String LOGTAG = "ReminderAppActivity";
	private ExpandableListView mList;
	private Button mCreateNew;
	private ReminderAdapter mAdapter;
	private ReminderApplication mApp;
	private AlarmManager mAlarmManager;
	private PendingIntent mPendingIntent;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.created);
        mApp = (ReminderApplication)getApplication();
        mList = (ExpandableListView)findViewById(R.id.reminderList);
        mAdapter = new ReminderAdapter(this, R.layout.group, R.layout.rowentry, mApp.getGroups(), mApp.getDataList());
        mList.setAdapter(mAdapter);
        mCreateNew = (Button)findViewById(R.id.createButton);
        mCreateNew.setOnClickListener(new OnClickListener () {
			public void onClick(View v) {
				Intent intent = new Intent(ReminderAppActivity.this, CreateNewActivity.class);
				startActivityForResult(intent, 1);
			}
        });
        /*if(mApp.isFirstStart()) {
        	mAlarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
        	//TODO : Intent
        	mPendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
        }*/
    }

    @Override
	protected void onPause() {
		Intent intent = new Intent(getBaseContext(), ReminderDataSaveService.class);
		startService(intent);
		super.onPause();
	}
    
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.mainmenu, menu);
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch(item.getItemId()) {
		case R.id.itemExit:
			finish();
		}
		return true;
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if(resultCode == RESULT_OK) {
			mAdapter.notifyDataSetChanged();
		}
	}
}